package com.lannuokeji.biz.sys.controller;


import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.lannuokeji.base.AController;
import com.lannuokeji.base.facade.PageRequest;
import com.lannuokeji.biz.sys.entity.Advice;
import com.lannuokeji.biz.sys.service.AdviceService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 用户意见反馈 前端控制器
 * </p>
 *
 * @author lannuoTeck
 * @since 2018-03-19
 */
@Api(description="用户意见建议、反馈")
@RestController
@RequestMapping("/sys/advice")
public class AdviceController extends AController {

	@Resource
	AdviceService adviceService;
	
	@ApiOperation(value = "查询本人提交的意见建议")
	@GetMapping()
	public Object getList(PageRequest pageRequest) {
		String userId = getUser();
		Page page = new Page(pageRequest.getCurrent(), pageRequest.getSize());
		page = adviceService.selectPage(page, new EntityWrapper<Advice>().eq("userId", userId));
		return setSuccessContent(page);
	}

	@ApiOperation(value = "提交意见建议")
	@PostMapping()
	public Object create(HttpServletRequest request, @RequestBody Advice entity) {
		entity.setCreateTime(new Date());
		entity.setUserId(getUser());
		boolean ret = adviceService.insertAllColumn(entity);
		if (ret) {
			return setSuccessContent("添加成功！");
		} else {
			return setErrorContent("添加失败！");
		}
	}
}

